package Controller_Servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import Model_Db.DbUtil;


@WebServlet("/Push_insert")
public class Push_insert extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8"); 
		response.setContentType("text/html;charset=UTF-8");
		String json = "";
	    String name=request.getParameter("name");
	    String date=request.getParameter("date");
	    String health=request.getParameter("health");
	    String tran=request.getParameter("iftranpro");
	    String msg=request.getParameter("message");
	    String sql1="Insert into Push_information(ad_name,date,health,if_Transprovincial,message) ";
	    String sql2="values('"+name+"','"+date+"','"+health+"','"+tran+"','"+msg+"')";
	    String sql=sql1+sql2;
	    DbUtil run=new DbUtil();
	    int n=run.updateSQL(sql);
	    System.out.print(n);
	    if (n >= 1) {
            json = "{\"flag\":\"提交成功\"}";
        } else {
            json = "{\"flag\":\"提交失败，请重试\"}";
        }
	    ObjectMapper mapper = new ObjectMapper();
        mapper.writeValue(response.getWriter(), json);
	    
//	    if(n>=1)
//	        request.getRequestDispatcher("success.jsp").forward(request,response);
//		else 
//		   request.getRequestDispatcher("error.jsp").forward(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
